﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using libDAL;

namespace libAddressBook.BUS
{
    sealed class clsBUSWebsiteEmailContactFax
    {
        private Queries _Query;
        private string strCompanyID = string.Empty;
        private string strContactType = string.Empty;

        private struct Queries
        {
            public string get_QueryContacts(string strCompanyID)
            {
                string strQuery = string.Empty;
                try
                {
                    strQuery = "SELECT AddressBookContactPersonID, comid, AddressBookContactPerson as [Contact Name], " +
                               "AddressBookContactNumberMobile as [Mobile No], " +
                               "AddressBookContactNumberLandLinePre as [Area Code], AddressBookContactNumberLandLine as [Land Line], " +
                               "AddressBookContactICCPassport as [ICC/Passport], AddressBookContactDefault as Dfault " +
                               "FROM AddressBookContactPersons " +
                               "WHERE comid = '" + strCompanyID + "'";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + " clsWebsiteEmailContactFax_Queries_get_QueryContacts");
                }
                return strQuery;
            }
        }

        private DataSet dsContactPerson;
        private cls_DAL _Dal;

        public string getset_ContactType
        {
            get
            {
                return strContactType;
            }
            set
            {
                strContactType = value;
            }
        }

        public string getset_CompanyID
        {
            get
            {
                return strCompanyID;
            }
            set
            {
                strCompanyID = value;
            }
        }

        public cls_DAL set_DataAccess
        {
            set
            {
                _Dal = value;
            }
        }

        public clsBUSWebsiteEmailContactFax()
        {
          //  dsContactPerson = new DataSet();
            _Query = new Queries();
        }

        public DataTable get_ContactPerson()
        {
            DataTable dt = new DataTable();
            if (dsContactPerson != null)
            {
                dt = dsContactPerson.Tables["ContactPerson-1"];
            }
            else
            {
                return set_ContactPerson();
            }
            return dt;
        }

        private DataTable set_ContactPerson()
        {
            DataTable dtContactPerson = new DataTable();
            try
            {
                if (getset_CompanyID.Trim() != string.Empty)
                {
                    dsContactPerson = new DataSet();
                    _Dal.set_DataWCardinality_ds(_Query.get_QueryContacts(getset_CompanyID), ref dsContactPerson, "ContactPerson-1");
                    dtContactPerson = dsContactPerson.Tables["ContactPerson-1"];
                }
                else
                {
                    dtContactPerson = dsContactPerson.Tables["ContactPerson-1"];
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_ContactPerson"); 
            }
            return dtContactPerson;
        }

    }

    
}
